#pragma once

#include <cstring>
#include <cassert>

namespace AsyncLogger {

	namespace detail {

		constexpr int kSmallBuffer = 4096;
		constexpr int kLargeBuffer = 4096 * 1024;

		template<int SIZE>
		class FixBuffer {
		public:
			FixBuffer() :cur_(data_) {

			}

			int avail() const {
				return end() - cur_;
			}

			int length() const {
				return cur_ - data_;
			}

			void add(int len) {
				cur_ += len;
				assert(avail() >= 0);
			}

			void append(const char* data, int len) {
				memcpy(cur_, data, len);
				add(len);
			}

			void bzero() {
				memset(data_, 0, SIZE);
			}

			void reset() {
				cur_ = data_;
			}

			char* data() {
				return data_;
			}

			char* current() {
				return cur_;
			}

		private:
			const char* end() const {
				return data_ + SIZE;
			}

		private:
			char data_[SIZE];
			char* cur_;
		};
	}
}